#ifndef TIMER_H
#define TIMER_H

#include <vector>
#include "bga/system/ConfigDLL.h"

namespace sf
{

class Thread;

}

/**
 * \namespace bga
 * \brief API namespace
 */
namespace bga
{

class BOARD_HELL_ENGINE TimerListener;

/**
 * This class defines a timer
 */
class BOARD_HELL_ENGINE Timer
{
    friend void startTimer(void* datas);    ///!< Callback function used as entry point of the thread

    public:
        /**
         * Constructor
         * \param time : an event will be throw all the time milliseconds
         *
         * Constructor. Default time is 1 second(1000 milliseconds
         */
        Timer(unsigned int time = 1000);

        /**
         * Destructor
         */
        virtual ~Timer();

        void start();   ///!< Start the timer
        void stop();    ///!< Stop the timer

        /**
         * \brief Set the time of the timer
         * \param time: new time of the timer in milliseconds
         *
         * Set the time of the timer. If the timer is currently running, this function has
         * no effect.
         */
        void setTime(unsigned int  time);

        /**
         * \brief To know if the timer is currently running
         * \return true if the timer is currently running, false else
         */
        bool isStarted() const;

        /**
         * \brief add a timer listener to the list of listener
         * \param listener : listener to add
         */
        void addTimerListener(TimerListener& listener);

    private:
        sf::Thread* thread;   ///!< Thread for the timer
        unsigned int  time;    ///!< Time in milliseconds
        bool isRunning;       ///!< To know if the timer is running

        std::vector< bga::TimerListener* > timerListeners;  ///!< List of timer listener

};

}

#endif // TIMER_H

